<template>
	<view>
		<indexTop></indexTop>
		<view class="stu_table">
		            <view class="add" @click="modelAddShow">
		            	添
						<br>
						加
		            </view>
		            <t-table>
		                <t-tr>
		                    <t-th>学号</t-th>
		                    <t-th>姓名</t-th>
		                    <t-th>年龄</t-th>
		                    <t-th>性别</t-th>
							 <t-th>班级</t-th>
							  <t-th>籍贯</t-th>
		                </t-tr>
						<view  v-for="(item,index) in stuList" @click="show(index)" :key="item">
							<t-tr >
							    <t-td>{{ index+1 }}
								
								</t-td>
							    <t-td>{{ item.name }}
								<view class="fix_goSelf" @click="goSelf(item.id)">
									
								</view>
								</t-td>
							    <t-td>{{ item.age }}</t-td>
							    <t-td>{{ item.sex }}</t-td>
								<t-td>{{ item.classNo }}</t-td>
								<t-td>{{ item.ji }}</t-td>
								<view class="del_xiu" v-show="itemIndex == index">
									<button size="mini" type="primary" @click="modelXiuShow(item)">修改</button>
									<button size="mini" type="warn" @click="del(item.id,index)">删除</button>
									
								</view>
							</t-tr>
						</view>
		                
		            </t-table>
		        </view>
				<model ref="model" :title="modelTitle" :studentInformation="studentInformation" @flush1="flush()"></model>
	</view>
</template>

<script>
	import indexTop from "../index/indexTop.vue"
	 import tTable from '@/components/t-table/t-table.vue';
	    import tTh from '@/components/t-table/t-th.vue';
	    import tTr from '@/components/t-table/t-tr.vue';
	    import tTd from '@/components/t-table/t-td.vue';
		import model from "@/pages/model/model"
	export default {
		components:{
			indexTop,
			tTable,
			tTh,
			tTr,
			tTd,
			model
		},
		data() {
			return {
				stuList:[],
				itemIndex:-1,
				studentInformation:{},
				modelTitle:""
			}
		},
		methods: {
			goSelf(id){
				console.log("aaaaaaaa")
				uni.navigateTo({
					url:"/pages/index/studentSelf?id="+id,
					
				})
			},
			flush(){
				console.log("--------flush------")
				let that = this;
				uni.request({
					url:"http://localhost:8080/user/findClass/"+that.stuList[0].classNo,
					success(res) {
						that.stuList = res.data
					}
				})
			},
			show(index){
				
				this.itemIndex = index;
				
			},
			modelAddShow(){
				this.modelTitle = "增加"
				this.studentInformation = {
					name:"",
					age:"",
					sex:"",
					classNo:"",
					ji:""
				},
				this.$refs.model.modelShow = true
			},
			modelXiuShow(item){
				this.modelTitle = "修改"
				this.studentInformation = item;
				this.$refs.model.modelShow = true
			},
			del(id,index){
				let that = this
				uni.request({
					url:"http://localhost:8080/user/deleteUser/"+id,
					success(res) {
						if(res.data){
							that.stuList.splice(index,1);
						}else{
							uni.showModal({
							    title: '错误',
							    content: '删除错误',
							    success: function (res) {
							        if (res.confirm) {
							            
							        } else if (res.cancel) {
							            
							        }
							    }
							});
						}
					}
				})
			},
			
		},
		onLoad(options) {
			let that = this;
			uni.request({
				url:"http://localhost:8080/user/findClass/"+options.classNo,
				success(res) {
					that.stuList = res.data
				}
			})
		}
	}
</script>

<style>
.del_xiu{
	position: absolute;
	right: 0rpx;
	top: 50%;
	transform: translateY(-50%);
}
.add{
	position: fixed;
	width: 80rpx;
	text-align: center;
	padding: 20rpx 0rpx;
	right: 4rpx;
	top: 50%;
	transform: translateY(-50%);
	background: #007AFF;
	color: white;
	
	z-index: 99;
}

.fix_goSelf{
	position: absolute;
	width: 100%;
	height: 100%;
	
}
</style>
